package com.thfw.test.view.adapter;

import android.content.Context;
import android.net.wifi.ScanResult;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.thfw.wmd.R;
import com.thfw.test.view.model.BluetoothLeDevice;

import java.util.ArrayList;
import java.util.List;

/**
 * Created BY Cuishikun
 * Created ON 2021/9/13
 * Package Name com.thfw.test.view.adapter
 **/
//自定义的适配器
public class WifiListAdapter extends BaseAdapter {
    private List<ScanResult> mlist;
    private Context mContext;

    public WifiListAdapter(Context context, List<ScanResult> list) {
        this.mContext = context;
        mlist = new ArrayList<ScanResult>();
        this.mlist = list;
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setListAll(List<ScanResult> list) {
        if (mlist == null) {
            mlist = new ArrayList<>();
        }
        mlist.clear();
        mlist.addAll(list);
        notifyDataSetChanged();
    }

    public void clear() {
        if (mlist != null) mlist.clear();
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Person person = null;
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.rtu_item, null);
            person = new Person();
            person.name = (TextView) convertView.findViewById(R.id.tv_name);
            convertView.setTag(person);
        } else {
            person = (Person) convertView.getTag();
        }
        person.name.setText(mlist.get(position).SSID);
        return convertView;
    }

    class Person {
        TextView name;
    }
}